<?php
// https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/submissions/
class Solution {

    /**
     * @param Integer[] $pushed
     * @param Integer[] $popped
     * @return Boolean
     */
    static function validateStackSequences($pushed, $popped) {
        $stack = array();
        $i = 0;
        foreach ($pushed as $push_number) {
            array_unshift($stack, $push_number);
            while (!empty($stack) && $stack[0] == $popped[$i]) {
                array_shift($stack);
                $i++;
            }
        }
        return empty($stack);
    }
}
$data = array(
    'A' =>    [1,2,3,4,5,6,7],
    'B' =>   [7,6,5,4,3,2,1],
    'C' =>   [5,6,4,3,7,2,1],
    'D' =>   [1,7,6,5,4,3,2],
    'E' =>   [3,2,1,7,5,6,4]
);
foreach ($data as $index => $item) {
    echo $index." - ".(Solution::validateStackSequences(array(1,2,3,4,5,6,7), $item) ? 1 : 0);
}